package com.dalor.phonesmanager.activity;

import android.app.Activity;
import android.app.ActivityOptions;
import android.content.Intent;
import android.os.Bundle;
import android.provider.ContactsContract;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.AdapterView;
import android.widget.GridView;
import android.widget.ImageView;

import com.dalor.phonesmanager.R;
import com.dalor.phonesmanager.adapter.PhonesAdapter;
import com.dalor.phonesmanager.bean.Image;
import com.dalor.phonesmanager.interfaces.OnPhoneItemListener;

import java.util.ArrayList;

/**
 * 作者： 吴昶 .
 * 时间: 2018/12/28 15:19
 * 功能简介：图片的列表展示
 */
public class PhonesActivity extends AppCompatActivity {

    private GridView gridView;
    private ArrayList<Image> phones;
    private PhonesAdapter phonesAdapter;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_phones);
        gridView=(GridView)findViewById(R.id.gv_phones);
        phonesAdapter=new PhonesAdapter(this);
        gridView.setAdapter(phonesAdapter);
        phonesAdapter.setItemListener(itemListener);
        phones=getIntent().getParcelableArrayListExtra("phones");
        phonesAdapter.setData(phones);

    }

    private void showBigImage(int i,ImageView imageView){
        Intent intent=new Intent(this,PagersPhonesActivity.class);
        intent.putExtra("imagePath",phones.get(i).path);
        intent.putExtra("index",i);
        Bundle bundle=new Bundle();
        bundle.putParcelableArrayList("phones",phones);
        intent.putExtras(bundle);
        startActivity(intent,ActivityOptions.makeSceneTransitionAnimation(this,imageView,"clickName").toBundle());
    }

    private OnPhoneItemListener itemListener=new OnPhoneItemListener() {
        @Override
        public void onPhoneClickItem(int position, ImageView imageView) {
            showBigImage(position,imageView);
        }
    };
}
